<script type="text/javascript" src="<?php echo $this->webroot.'/misc/pluges';?>/jquery-autocomplete/lib/jquery.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot.'/misc/pluges';?>/jquery-autocomplete/jquery.autocomplete.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->webroot.'/misc/pluges';?>/jquery-autocomplete/jquery.autocomplete.css" />

<script language="javascript">
    $(document).ready(function() {
        $("#search").autocomplete(
        "<?php echo url_for("bin/join_us.php");?>",
        {
            delay:10,
            minChars:1,
            matchSubset:1,
            matchContains:1,
            cacheLength:10,
            autoFill:false
        }
        ).result(function(){
             var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
             var email_val = $("#search").val();
             if(search_str.test(email_val)){
                checkEmail();
             }else{
                 $("#search").val('email格式错误.');
             }
        });
    });

    function checkEmail(){
       $.ajax({
          url: "<?php echo url_for('user/check_email');?>",
          dataType: "html",
          success:function(data){
            if(data!='ok'){
                $("#search").val('email已经注册.');
            }
          },error:function(){
              alert('error');
          }
       });
    }
    
    function clearValue(id,value) {
        if($("#"+id).val() == value){
            $("#"+id).val('');
        }
    }
</script> 
<input id="search" size="80" onclick="clearValue('search','email已经注册.');"/>